package com.example.zzl.model.HomeFragment;

import android.content.Context;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import com.example.zzl.model.bean.Home.Special;
import com.example.zzl.model.cans.HomeUrl;
import com.example.zzl.utils.specification.VolleySingleton;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

//import java.lang.reflect.Type;

/**
 * Created by ligg on 2017/2/10.
 */

public class SpecialModel implements Response.Listener<String> {

    private Context context;
    private SpecialCallbackM callback;
    private List<Special.ResultBean> list;

    @Override
    public void onResponse(String response) {
        list = new ArrayList<Special.ResultBean>();
        Type type = new TypeToken<List<Special.ResultBean>>() {
        }.getType();
        list = new Gson().fromJson(response, type);
        callback.loadFinish();
    }

    public interface SpecialCallbackM {
        void loadFinish();
    }

    public SpecialModel(Context context, SpecialCallbackM callback) {
        this.context = context;
        this.callback = callback;
    }

    public void loadData() {
        StringRequest stringRequest = new StringRequest(HomeUrl.Special, this, VolleySingleton.volleySingleton);
        VolleySingleton.volleySingleton.getRequestQueue().add(stringRequest);
    }

    public List<Special.ResultBean> getList() {
        return list;
    }
}
